package com.neuedu.qian.controller;

import com.neuedu.qian.entity.ClassInfo;
import com.neuedu.qian.service.IClassInfoService;
import com.neuedu.qian.vo.ResponseData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author lu
 * Date   2025-07-31 09:49:29
 */
@Log4j2
@RequestMapping("/qian/api/class/")
@RestController
@Tag(name = "班级管理控制器")
public class ClassInfoController {

    @Autowired
    @Qualifier("classInfoService")
    private IClassInfoService classInfoService;
    //传统API+RESTful API

    /**
     * 创建班级
     *
     * @param c
     * @return
     */
    @PostMapping("create")
    @Operation(summary = "新增班级")
    //配置参数
    @Parameters({
            @Parameter(name = "college", description = "班级所属学院名称", required = true),
            @Parameter(name = "classNo", description = "班级编号", required = true),
            @Parameter(name = "className", description = "班级名称", required = true)
    })
    public ResponseData createClass(@Parameter(hidden = true) @RequestBody ClassInfo c) {
        return classInfoService.insertOne(c);
    }

    /**
     * 根据班级ID删除班级记录
     * true:表示删除成功
     * false:表示删除失败,即没有满足条件记录或记录不存在
     *
     * @param classId
     * @return
     */
    @DeleteMapping("deleteById/{classId}")
    @Operation(summary = "根据ID删除班级")
    @Parameter(name = "classId", description = "班级ID", required = true)
    public ResponseData deleteById(@PathVariable("classId") int classId) {
        boolean result = classInfoService.removeById(classId);
        return ResponseData.success(result);
    }

    /**
     * 根据班级ID修改班级信息
     * true:表示修改成功
     * false:表示修改失败,即没有满足条件记录或记录不存在
     *
     * @param c
     * @return
     */
    @PatchMapping("updateById")
    @Operation(summary = "根据ID修改班级")
    @Parameters({
            @Parameter(name = "classId", description = "班级ID", required = true),
            @Parameter(name = "college", description = "班级所属学院名称"),
            @Parameter(name = "classNo", description = "班级编号"),
            @Parameter(name = "className", description = "班级名称")
    })
    public ResponseData modify(@RequestBody ClassInfo c) {
        return classInfoService.updateOne(c);
    }

    /**
     * 根据ID查询班级信息
     *
     * @param classId
     * @return
     */
    @GetMapping("getById/{classId}")
    @Operation(summary = "根据ID查询班级")
    @Parameter(name = "classId", description = "班级ID", required = true)
    public ResponseData getById(@PathVariable("classId") int classId) {
        ClassInfo classInfo = classInfoService.getById(classId);
        return ResponseData.success(classInfo);
    }

    /**
     * 根据班级编号、班级名称、班级所属学院名称查询班级列表
     *
     * @param keyword
     * @param c
     * @return
     */
    @GetMapping("list")
    @Operation(summary = "多条件查询班级")
    @Parameters({
            @Parameter(name = "keyword", description = "班级编号、班级名称、班级所属学院名称", required = false),
            @Parameter(name = "recordStatus", description = "记录状态(1:使用;9:停用)", required = false)
    })
    //@Parameter(hidden = true):在knife4j接口调试界面不出现形参 c
    public ResponseData getList(String keyword, @Parameter(hidden = true) ClassInfo c) {
        List<ClassInfo> list = classInfoService.selectList(keyword, c);
        return ResponseData.success(list);
    }
}